home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14472 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  75 lines

  1. Newsgroups: comp.lang.c
  2. Path: new-news.sprintlink.net!eskimo!news
  3. From: mag@eskimo.com (mAg)
  4. Subject: Re: #include "" for large programs.
  5. X-Nntp-Posting-Host: tia1.eskimo.com
  6. Message-ID: <Dpw2FI.KJt@eskimo.com>
  7. Sender: news@eskimo.com (News User Id)
  8. Organization: *.*
  9. X-Newsreader: WinVN 0.93.10
  10. References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
  11. Date: Mon, 15 Apr 1996 05:40:28 GMT
  12.  
  13. In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan> (Thu, 11 Apr 1996 20:05:59 
  14. -0400), cdiaz@eng.usf.edu says :
  15. >
  16. >Hello!
  17. > I've been writing short two part programs using the #include "filename"
  18. >preprocessor.
  19. > I call one file main.c and the other part2.c, for which there is a
  20. >prototype header file part2.h.
  21. > All works well when I compile the programs, except when  part2.h has
  22. >#define constants (I've been advised by my professor to use #define for
  23. >constants over 'const type var_name'). My compiler returns a fatal error
  24. >reporting that the symbol in the #define is not defined.
  25. > For example if #define EQUAL 0 is part of part2.h, I'm told that the
  26. >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
  27. >told that I've defined EQUAL  TWICE, once in part2.h and again within
  28. >main. The book we're using in class is not helping at all in this subject,
  29. >and I cannot figure out why everything else is recognized, except #define
  30. >constants. Can anyone here help? If the answer to this is in the FAQ, just
  31. >tell me where to download it from. Thanks!
  32. >
  33. >-Carlos E. Diaz
  34. >
  35. >
  36.  
  37. The constants should be declared only in one file.
  38.  
  39. Here is an example of how it should be done. Let us assume that we have a constant 
  40. MAX_LEN = 80.
  41.  
  42.  
  43.  
  44. /* myprog.h */
  45. #define MAX_LEN 80
  46.  
  47. /* === */
  48.  
  49.  
  50.  
  51. /* main.c */
  52. #include "myprog.h"
  53.  
  54. /* use MAX_LEN */
  55.  
  56. /* === */
  57.  
  58.  
  59.  
  60. /* subpart1.c */
  61.  
  62. /* use MAX_LEN */
  63.  
  64. /* === */
  65.  
  66. -- 
  67. /* --------------------------------------------------------
  68.                       MAG@ESKIMO.COM
  69. http://www.eskimo.com/~mag/index.html
  70. ***********************************************************
  71. To understand recursion one must first understand recursion
  72. ***********************************************************
  73. -------------------------------------------------------- */
  74.  
  75.